<script setup lang="ts">
import { Document, Menu as IconMenu, Location, Setting, Message } from "@element-plus/icons-vue";

// 子组件接受父组件传递的数据
// 定义menuList属性，接受父组件传递的menuList数据
defineProps(["menuList"]);
</script>

<!-- v-slot -->
<!-- <template #title> ==> <template v-slot:title>  -->
<template>
    <template v-for="item in menuList" :key="item.path">
        <!-- 判断该菜单项是否有子菜单 -->
        <el-sub-menu v-if="item.children && item.children.length > 0" :index="item.path">
            <template #title>
                <el-icon>
                    <!-- 通过动态组件展示图标 -->
                    <component :is="item.meta.icon"></component>
                </el-icon>
                <span>{{ item.meta.title }}</span>
            </template>
            <!-- 递归调用，将子菜单传递给组件处理 -->
            <menu-item :menuList="item.children"></menu-item>
        </el-sub-menu>
        <el-menu-item v-else :index="item.path">
            <el-icon>
                <component :is="item.meta.icon"></component>
            </el-icon>
            <span>{{ item.meta.title }}</span>
        </el-menu-item>
    </template>
</template>
